// pages/Main/mainIndex/mainIndex.js
var common = require('../../../utils/common.js')
var businessLogic = require('../../../utils/NetWork/Model/MainbusinessLogic.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
   zuoye:[],
   ur:'',
   title:'',
   num: 1,
   scrollHeight: 0,

  },

  /**
   * 生命周期函数--监听页面加载
   * 
   */
  


  onLoad: function (options) {
    let c = common.Getorgid();
    var scrollHeight = scrollHeight;
    wx.getSystemInfo({
      success: function (res) {
        scrollHeight = res.windowHeight
      }
    }); 
    this.setData({
      orgid: c.orgid,
      userid: c.userid,
      classid:options.id,
      scrollHeight: scrollHeight,
    });
    this.list();
  }, 
   bindDownLoad: function () {
    if (this.data.lenpage > this.data.num) {
      var di = this.data.num;
      var di = di + 1;
      this.setData({
        num: di
      });
      console.log(di)
      this.list();
    } else {
      common.showToast("到底了", "loading");
    }
  }, 
  //6.4.1
  list: function () {
    common.showLoading("加载中", "loading");
    let params = { "page": this.data.num, "num": 15,"orgid": this.data.orgid, "userid": this.data.userid, "ur": this.data.ur, "searchField": "seedeps,pgmemberid,title", "searchValue": "" + this.data.classid + "," + this.data.userid + "," + this.data.title + ""}
    businessLogic.QueryOperation(params, (res) => {
      //console.log("6.4.1", res)
       var page = res.page
      var res = res.infos;
      var bbb = this.data.zuoye
      for (var a = 0; a < res.length; a++) {
        bbb.push(res[a]);
      } 
      this.setData({
        zuoye:bbb,
        lenpage: page.pages
      })
      common.hideLoading();
    })
  },
//search
  bindKeyInput: function (e) {
    this.setData({
      title: e.detail.value
    })
  },
  search2: function (event) {
    common.showLoading("加载中", "loading");
    let params = { "orgid": this.data.orgid, "userid": this.data.userid, "ur": this.data.ur, "searchField": "seedeps,pgmemberid,title", "searchValue": "" + this.data.classid +"," + this.data.userid + "," + this.data.title +"" }
    businessLogic.QueryOperation(params, (res) => {
      var res = res.infos;
      this.setData({
        zuoye: res
      });
      common.hideLoading();
    });
  }, 

  classChart:function(event){
    wx.navigateTo({
      url: "../classChart/classChart?paperid=" + event.currentTarget.dataset.paper + "&&examid=" + event.currentTarget.dataset.exam+"&&classid="+this.data.classid
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.ConditionList = this.selectComponent("#ConditionList");
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.ConditionList = this.selectComponent("#ConditionList");
    this.ConditionList.close();
    this.shanxuan();
  },
  isShow: function (e) {
    this.ConditionList.isShow();
    this.list();
  },
  //筛选
  shanxuan: function (ur) {
    if (ur == '' || ur == undefined) {
      var ur = '';
      let params = { classid: "5b3bbf31-44be-483b-93c5-7229c486b85d", "orgid": this.data.orgid,  "ur": ur }
      businessLogic.getCondition(params, (res) => {
        //渲染页面
        this.ConditionList.conditionList(res, ur);
      })
    } else {
      console.log(ur.detail)
      let params = { classid:"5b3bbf31-44be-483b-93c5-7229c486b85d", "orgid": this.data.orgid,  "ur": ur.detail[0] }
      businessLogic.getCondition(params, (res) => {
        //渲染页面
        this.setData({
          ur: ur.detail[0]
        })
        this.ConditionList.conditionList(res, ur.detail[0]);

      })
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})